
import 'dart:convert';

import 'package:ichinesereader/models/book/BookLevel.dart';
import 'package:ichinesereader/models/student/StudentItem.dart';
import 'package:ichinesereader/models/teacher/TeacherDto.dart';
import 'package:ichinesereader/models/common/Settings.dart';

List<SchoolClasses> schoolClassesFromJson(String str) =>
    List<SchoolClasses>.from(
        json.decode(str).map((x) => SchoolClasses.fromJson(x)));

String schoolClassesToJson(List<SchoolClasses> data) =>
    json.encode(List<dynamic>.from(data.map((x) => x.toJson())));

class SchoolClasses {
  SchoolClasses({
    this.classCode,
    this.classId,
    this.classLevel,
    this.className,
    this.createDate,
    this.gameDisable,
    this.level,
    this.numBooks,
    this.numOfAssignment,
    this.numQuizzes,
    this.rank,
    this.settings,
    this.shelf,
    this.students,
    this.teachers,
    this.viewReport,
  });

  String? classCode;
  String? classId;
  Level? classLevel;
  String? className;
  DateTime? createDate;
  bool? gameDisable;
  String? level;
  int? numBooks;
  int? numOfAssignment;
  int? numQuizzes;
  int? rank;
  Settings? settings;
  String? shelf;
  List<StudentItem>? students;
  List<TeacherDto>? teachers;
  bool? viewReport;

  factory SchoolClasses.fromJson(Map<String, dynamic> json) => SchoolClasses(
        classCode: json["classCode"],
        classId: json["classId"],
        classLevel: Level.fromJson(json["classLevel"]),
        className: json["className"],
        createDate: DateTime.parse(json["createDate"]),
        gameDisable: json["gameDisable"],
        level: json["level"],
        numBooks: json["numBooks"],
        numOfAssignment: json["numOfAssignment"],
        numQuizzes: json["numQuizzes"],
        rank: json["rank"],
        settings: Settings.fromJson(json["settings"]),
        shelf: json["shelf"],
        students: List<StudentItem>.from(
            json["students"].map((x) => StudentItem.fromJson(x))),
        teachers: List<TeacherDto>.from(
            json["teachers"].map((x) => TeacherDto.fromJson(x))),
        viewReport: json["viewReport"],
      );

  Map<String, dynamic> toJson() => {
        "classCode": classCode,
        "classId": classId,
        "classLevel": classLevel?.toJson(),
        "className": className,
        "createDate": createDate?.toIso8601String(),
        "gameDisable": gameDisable,
        "level": level,
        "numBooks": numBooks,
        "numOfAssignment": numOfAssignment,
        "numQuizzes": numQuizzes,
        "rank": rank,
        "settings": settings?.toJson(),
        "shelf": shelf,
        "students": List<dynamic>.from(students!.map((x) => x.toJson())),
        "teachers": List<dynamic>.from(teachers!.map((x) => x.toJson())),
        "viewReport": viewReport,
      };
}
